/*  This file is part of LibGChart.
 *
 * AUTHORS
 *       Sascha Dewald        <sascha.dewald@googlemail.com>
 *
 * Copyright (C) 2009 Sascha Dewald
 *
 *  
 *  
 *  LibGChart is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with LibGChart.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
//using Gdk;

using Cairo;

namespace LibGChart
{
	//FIXME: there must be a better way, to get a static class + static member, with possibility to construct/destruct
	internal class DestructHelper
	{
		internal Cairo.Context offScreenContext;
		
		internal DestructHelper()
		{
			//FIXME: is there a better way, to get a Cairo.Context for offscreen calculation of the fontSize
			offScreenContext = Gdk.CairoHelper.Create(Gdk.Screen.Default.RootWindow);
		}
		
		~DestructHelper()
		{
			Console.WriteLine("Clean up.");
			
			// Cleanup the Cairo.Context, because Garbage Collection is not perfect in the Cairo library
			((IDisposable) offScreenContext.Target).Dispose();                                      
			((IDisposable) offScreenContext).Dispose();
		}
		
	}
	
	/**
	 *  a helper class, to get a offscreen context
	 */
	internal static class OffScreenContextHelper
	{
		private static DestructHelper dh; // tmpContext to calculate the space what the font needs
		
		public static Cairo.Context OffscreenContext
		{
			get {
				if (dh == null)
				{
					dh = new DestructHelper();
				}
				
				return dh.offScreenContext;
			}
		}
	}
	
}